<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>sort</title>
	<!--<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
</head>
<body>
<script>
	//排序算法
	//通常规定
	// x > y 返回 1
	// x === y 返回 0
	// x < y 返回 -1
	let arr1 = ["Google","Apple","Baidu"];
	var arr1Result = arr1.sort();
	console.log("arr1:" + arr1);
	console.log("arr1Result:" + arr1Result);

	//sort()方法会把元素转换成String再进行排序
	let arr2 = [1,10,20,2];
	let arr2Result = arr2.sort();
	console.log("arr2:" + arr2);
	console.log("arr2Result:" + arr2Result);

	//正序
	let arr3 = [10,20,1,2];
	let arr3Result = arr3.sort(function (x,y) {
		if (x < y) {
			return -1;
		}
		if (x > y) {
			return 1;
		}
		return 0;
	});

	console.log("arr3:" + arr3);
	console.log("arr3Result:" + arr3Result);
	let arr3Result1 = arr3.sort(function (x,y) {
		if (x < y) {
			return 1;
		}
		if (x > y) {
			return -1;
		}
		return 0;
	});
	console.log("arr3Result1:" + arr3Result1);

</script>
</body>
</html>